package cn.iocoder.yudao.module.jifenyuan.controller.app.wallet;

import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.jifenyuan.dal.redis.JifenyuanLockRedisDao;
import org.redisson.api.RedissonClient;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.jifenyuan.controller.app.wallet.vo.*;
import cn.iocoder.yudao.module.jifenyuan.dal.dataobject.wallet.WalletDO;
import cn.iocoder.yudao.module.jifenyuan.convert.wallet.WalletConvert;
import cn.iocoder.yudao.module.jifenyuan.service.wallet.WalletService;

@Tag(name = "用户 APP - 记分员 钱包")
@RestController
@RequestMapping("/jifenyuan/wallet")
@Validated
public class AppWalletController {

    @Resource
    private WalletService walletService;
    @Resource
    private JifenyuanLockRedisDao jifenyuanLockRedisDao;





//    @GetMapping("/testAddCoin")
//    @Operation(summary = "测试添加金币")
//    @PreAuthenticated
//    public CommonResult<Boolean> testAddCoin() {
//        jifenyuanLockRedisDao.lock(SecurityFrameworkUtils.getLoginUserId(), 1000L, new Runnable() {
//            @Override
//            public void run() {
//                walletService.addWalletCoin(SecurityFrameworkUtils.getLoginUserId(),10L);
//            }
//        });
//
//        return success(true);
//    }

//    @GetMapping("/testAddVip")
//    @Operation(summary = "测试添加VIP")
//    @PreAuthenticated
//    public CommonResult<Boolean> testAddVip() {
//        jifenyuanLockRedisDao.lock(SecurityFrameworkUtils.getLoginUserId(), 1000L, new Runnable() {
//            @Override
//            public void run() {
//                walletService.addWalletVip(SecurityFrameworkUtils.getLoginUserId(),30);
//            }
//        });
//
//        return success(true);
//    }



//    @PostMapping("/create")
//    @Operation(summary = "创建记分员 钱包")
//
//    public CommonResult<Long> createWallet(@Valid @RequestBody AppWalletCreateReqVO createReqVO) {
//        return success(walletService.createWallet(createReqVO));
//    }
//
//    @PutMapping("/update")
//    @Operation(summary = "更新记分员 钱包")
//
//    public CommonResult<Boolean> updateWallet(@Valid @RequestBody AppWalletUpdateReqVO updateReqVO) {
//        walletService.updateWallet(updateReqVO);
//        return success(true);
//    }
//
//    @DeleteMapping("/delete")
//    @Operation(summary = "删除记分员 钱包")
//    @Parameter(name = "id", description = "编号", required = true)
//
//    public CommonResult<Boolean> deleteWallet(@RequestParam("id") Long id) {
//        walletService.deleteWallet(id);
//        return success(true);
//    }
//
//    @GetMapping("/get")
//    @Operation(summary = "获得记分员 钱包")
//    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//
//    public CommonResult<AppWalletRespVO> getWallet(@RequestParam("id") Long id) {
//        WalletDO wallet = walletService.getWallet(id);
//        return success(WalletConvert.INSTANCE.convert(wallet));
//    }
//
//    @GetMapping("/list")
//    @Operation(summary = "获得记分员 钱包列表")
//    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
//
//    public CommonResult<List<AppWalletRespVO>> getWalletList(@RequestParam("ids") Collection<Long> ids) {
//        List<WalletDO> list = walletService.getWalletList(ids);
//        return success(WalletConvert.INSTANCE.convertList(list));
//    }
//
//    @GetMapping("/page")
//    @Operation(summary = "获得记分员 钱包分页")
//
//    public CommonResult<PageResult<AppWalletRespVO>> getWalletPage(@Valid AppWalletPageReqVO pageVO) {
//        PageResult<WalletDO> pageResult = walletService.getWalletPage(pageVO);
//        return success(WalletConvert.INSTANCE.convertPage(pageResult));
//    }
//
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出记分员 钱包 Excel")
//
//    @OperateLog(type = EXPORT)
//    public void exportWalletExcel(@Valid AppWalletExportReqVO exportReqVO,
//              HttpServletResponse response) throws IOException {
//        List<WalletDO> list = walletService.getWalletList(exportReqVO);
//        // 导出 Excel
//        List<AppWalletExcelVO> datas = WalletConvert.INSTANCE.convertList02(list);
//        ExcelUtils.write(response, "记分员 钱包.xls", "数据", AppWalletExcelVO.class, datas);
//    }

}
